/*************

new_wireless.c, written from dispatch.c by lconstano, some cleanups by scythe

*************/

#include "sysdef.h"
#include "new_wireless.h"

//Only used here
//Would generate warnings for other obj if defined static in a header
//Would not be linkable in not defined static but in a header
static int wl3501_chan2freq[] =
{
   [0]  = 2412, [1]  = 2417, [2]  = 2422, [3]  = 2427, [4] = 2432,
   [5]  = 2437, [6]  = 2442, [7]  = 2447, [8]  = 2452, [9] = 2457,
   [10] = 2462, [11] = 2467, [12] = 2472, [13] = 2477,
};

// channel number -> channel freq.
void ChannelNumToFreq(u8 NetworkType, u8 ChannelNumber, u32 *freq)
{
	*freq = wl3501_chan2freq[ChannelNumber];
}

// channel freq. -> channel number, freq in MHz
void FreqToChannelNum(u8 Band, u8 *ChannelNumber, u32 freq)
{
	switch ( Band ) {
	case BAND_TYPE_DSSS:
	case BAND_TYPE_OFDM_24:
		if (freq < 2484)
			*ChannelNumber = (u8)((freq-2407)/5);
		else
			*ChannelNumber = 14;
		break;
	case BAND_TYPE_OFDM_5:
		if (freq < 4920)
			*ChannelNumber = (u8)((freq-5000)/5);
		else
			*ChannelNumber = (u8)((freq-4000)/5);
		break;
	default:
		break;
	}
}

int test_get_name(struct net_device *dev,
			 struct iw_request_info *info, char *name, char *extra)
{
	strcpy(name, "w35und");
	return 0;
}

int test_set_scan(struct net_device *dev,
			 struct iw_request_info *info, struct iw_point *srq, char *extra)
{
	PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
	DEBUG("SET SCAN\n");
	sme_set_bssid_list_scan( Adapter, NULL );
	psSCAN->ScanTimeStamp++;

	/* We do everything in get_scan */
	return 0;
}

int test_get_scan(struct net_device *dev,
		  struct iw_request_info *info, struct iw_point *srq, char *extra)
{
	int  i;
	struct iw_event iwe;
	char *cev = extra;
	s32 rssi;
	char *end_buf = extra + IW_SCAN_MAX_DATA;
	u8 count;
	PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
	phw_data_t pHwData=&(Adapter->sHwData);

	WB_BSSDESCRIPTION	*pscan_bss = NULL;
	u32 freq;
	u8 scannedESSID[32];
	int  essid_len;

	sme_get_scan_bss_count(Adapter, &count);

	DEBUG(" perform scanning \n");
	DEBUG(" Total %d STAs have found\n", count);

	if (count <= 0)
		return 0;
	for (i=0; i< count; i++) {
		memset(scannedESSID, 0x00, 32);
		essid_len = 0;
		rssi = 0;
		sme_get_scan_bss(Adapter, i, (void*)&pscan_bss);

		Assemble_IE(Adapter, pscan_bss->wIndex);
		DEBUG("BSSTYPE: %d\n", pscan_bss->bBssType);
		strcpy(scannedESSID, pscan_bss->SSID.SSID);
		essid_len = pscan_bss->SSID.Length;

		/* during tests, an outside ap appears twice, ( same mac, same freq, etc ), one essid is empty, the second one is ok,
		 * so i discard for now the esidd_len = 0 */
		if (!essid_len)
			continue;
		DEBUG("SSID length:%d ,SSID: %s\n",pscan_bss->SSID.Length,pscan_bss->SSID.SSID);
		//	     DataDmp(pscan_bss->SSID.SSID, pscan_bss->SSID.Length, 0);

		//ACa esta en 1
		DEBUG("BSSTYPE: %d\n",pscan_bss->bBssType);
		iwe.cmd = SIOCGIWAP;
		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
		//REVISTAR ESTO, COPIA MAL
		memset(iwe.u.ap_addr.sa_data,0x00,6);
		memcpy( iwe.u.ap_addr.sa_data, pscan_bss->abBssID, 6);
		cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_ADDR_LEN);

		DEBUG("WESSID");
		//ACA YA PASO a 0 , cambio las capa.......... porq?
		DEBUG("BSSTYPE: %d\n",pscan_bss->bBssType);
		//----------------------------------------------------
		iwe.cmd = SIOCGIWESSID;
		iwe.u.data.length = essid_len;
		iwe.u.data.flags = 1;
		if (iwe.u.data.length > 32)
			iwe.u.data.length = 32;

		DEBUG("IW Lengt: %d -> %d\n",iwe.u.data.length,essid_len);
		cev = iwe_stream_add_point(cev, end_buf, &iwe, scannedESSID);
		DEBUG("BSSTYPE: %d\n",pscan_bss->bBssType);
		DEBUG("FREQ");
		//-----------------------------------------------------
		iwe.cmd = SIOCGIWFREQ;

		ChannelNumToFreq(pscan_bss->band,
				 pscan_bss->DS_Parameter_Set.Current_Channel,
				 &freq);
		//iwe->u.freq.m = freq;
		iwe.u.freq.m = freq;

		//memcpy( &(iwe->u.freq.m), &freq, sizeof(iwe->u.freq.m) );
		iwe.u.freq.e = 6;
		cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_FREQ_LEN);
		DEBUG("BSSTYPE: %d\n",pscan_bss->bBssType);
		//------------------------------------------------------
		iwe.cmd = SIOCGIWMODE;

		DEBUG("Mode: %d     (ESS %d) (IBSS %d)\n", pscan_bss->bBssType,ESS_NET,IBSS_NET);
		if (pscan_bss->bBssType == ESS_NET)
		{
			DEBUG("bBssType is ESS_NET\n");
			iwe.u.mode =IW_MODE_INFRA;
		}
		else if (pscan_bss->bBssType == IBSS_NET)
		{
			DEBUG("bBssType is IBSS_NET\n");

			iwe.u.mode=IW_MODE_ADHOC;
		}

		cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_UINT_LEN);

		//------------------------------------------------------
		iwe.cmd = IWEVQUAL;

		//rssi, quality will depend on this value ( dont know h' to get noise lvl from ch)
		//GET_QUALITY should get a percentage based on min and max rssi reported by the network interface ...
		rssi = hal_get_rssi(pHwData, pscan_bss->HalRssi,MAX_ACC_RSSI_COUNT);
		iwe.u.qual.level = rssi;
		iwe.u.qual.updated = 7;

		iwe.u.qual.qual = GET_QUALITY_PERCENTAGE(rssi);
		cev = iwe_stream_add_event(cev, end_buf, &iwe, IW_EV_QUAL_LEN);
		//iwe->u.qual.level = pscan_bss->HalRssi;

		//-------------------------------------------------------
		iwe.cmd = SIOCGIWENCODE;
		iwe.u.data.length = 0;

		DEBUG("Privacy: 0x%x\nInfo wValue: 0x%x\n",pscan_bss->CapabilityInformation.Capability.CF_Privacy,
		      pscan_bss->CapabilityInformation.wValue);
		if( (!pscan_bss->CapabilityInformation.Capability.CF_Privacy)
		    && !(pscan_bss->CapabilityInformation.wValue & BIT(4)) )
		{
			iwe.u.data.flags = IW_ENCODE_DISABLED;
		}
		else
			iwe.u.data.flags = IW_ENCODE_ENABLED;
		cev = iwe_stream_add_point(cev, end_buf, &iwe, NULL);
	}

	srq->length = cev - extra;
	srq->flags = 0;

	return 0;
}


int test_get_freq(struct net_device *dev,
			 struct iw_request_info *info, struct iw_freq *freq, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   u8   ConnectStatus;
   u8   CurrentChan, CurrentBand;
   u32   freqc;
   phw_data_t pHwData=&(Adapter->sHwData);
   sme_get_connect_status(Adapter, &ConnectStatus);

   DEBUG("get_freq:");
   if (ConnectStatus == MEDIA_STATE_CONNECTED)
     {

	sme_get_current_channel(Adapter, &CurrentChan);
	sme_get_current_band(Adapter, &CurrentBand);
	ChannelNumToFreq(CurrentBand, CurrentChan, &freqc);
	freq->m = freqc;
	freq->e = 6;
	DEBUG("Sett...\n");

     }

   else
     {
	if( pHwData->Channel < 1 || pHwData->Channel > 14 )
	  pHwData->Channel = 1;

	//Nos basamos en datos ya seteados si no esta conectado
# ifdef WEXT_USECHANNELS
	freq->m = pHwData->Channel;
	freq->e = 0;
# else

	freq->m = wl3501_chan2freq[pHwData->Channel-1] * 100000;
	freq->e = 1;
# endif
	DEBUG("Not Connected :(");
     }

   return 0;
}

int test_set_freq(struct net_device *dev,
			 struct iw_request_info *info, struct iw_freq *freq, char *extra)
{
   DEBUG("SET FREQ\n");
   return 0;
}

int test_get_range(struct net_device *dev,
			  struct iw_request_info *info, struct iw_point *wrq, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   int i=0;
   u8   ConnectStatus;
   //data reported on product list ( CN402USB ), if it's already connected will report AP support rates
   //5.5 should appear when connected to an Ap.
   //Not here cause set_rate in original driver do not accept ~5 as new rate ( Note by : lCosta )
   u8 supported_rates_by_vendor[MAX_RATES_BY_VENDOR]=
     {
	1,2,11,6,9,12,18,24,36,48,54

     };
   struct iw_range *range = (struct iw_range *)extra;
   wrq->length = sizeof(struct iw_range);

   DEBUG2("get_range()");
   memset(range, 0, sizeof(struct iw_range));
   range->we_version_compiled = WIRELESS_EXT;

   range->we_version_source = WIRELESS_EXT;

   //Fill Default / 802.11/b ( placa soporta /g) 5.9 Mpbs ( based on standard )
   range->throughput = (5.9) * 1000 * 1000;

   range->max_qual.qual = 101;
   range->max_qual.level = 0;
   range->max_qual.noise = -96;
   range->max_qual.updated = 7;
   range->retry_capa = IW_RETRY_LIMIT;
   range->retry_flags = IW_RETRY_LIMIT;
   range->min_retry = 0;
   range->max_retry = 255;
   range->sensitivity  = 3;

   //i keep compat, with powerdb table of winbound, just IW_TXPOW_RANGE , doesn't matter really...
   //You can check the table at sme_api.h for full conversion
   range->txpower[0] = PowerDbToMw[1];
   range->txpower[1] = PowerDbToMw[2];
   range->txpower[2] = PowerDbToMw[3];
   range->txpower[3] = PowerDbToMw[4];
   range->txpower[4] = PowerDbToMw[5];
   range->txpower[5] = PowerDbToMw[6];
   range->txpower[6] = PowerDbToMw[7];
   range->txpower[7] = PowerDbToMw[8];
   range->num_txpower = 8 ;
   range->txpower_capa = IW_TXPOW_MWATT;

   range->min_rts = 0;
   range->min_frag =0;// 2346; // DEFAULT
   range->max_rts = 2347; //DEFAULT.....
   range->min_frag = 2500 ; // Max?
   //se podrian mostrar siempre 14 y listo......
   switch( psLOCAL->region)
     {

	//EUROPE
      case 1:
	range->num_channels = 13;
	break;
	//JAPAN
      case 2:
        range->num_channels = 14;
	break;
      default:

        range->num_channels = 11;
	break;
     }

   for(i=0;i< range->num_channels && i < IW_MAX_FREQUENCIES;i++)
     {
	range->freq[i].i = i + 1;
	range->freq[i].m = wl3501_chan2freq[i] * 100000;
	range->freq[i].e = 1;

     }

   range->num_frequency = i;
   range->encoding_size[0]=5;
   range->encoding_size[1]=13;
   range->num_encoding_sizes = 2;
   range->max_encoding_tokens = KEYS_AVAILABLE;

   //If its connected show AP supported rates, else show "Vendor Support Rates" based on two modes only ( b/g or b )
   DEBUG2("GET STATUS!!!!!!\n");

   sme_get_connect_status(Adapter, &ConnectStatus);
   DEBUG2("END GET STATUS\n");
   if (ConnectStatus == MEDIA_STATE_CONNECTED)
     {
	range->num_bitrates =  psLOCAL->NumOfSRate;
	for(i=0;i< psLOCAL->NumOfSRate;i++)
	  {
	     //actually, its supported rates, same as the array......
	     range->bitrate[i]=   psLOCAL->SRateSet[i]*500000;

	  }

	DEBUG2("SHOW AP RATES!!!\n");
     }
   else
     {
	//should show B And G RateS? or Only G here? Anyway, its just report, shouldn't affect
        if (psLOCAL->bMacOperationMode == MODE_802_11_BG_IBSS)
	  {
	     DEBUG("RATES BG\n");

	     range->num_bitrates = MAX_RATES_BY_VENDOR;
	     for(i=0;i<MAX_RATES_BY_VENDOR;i++)
	       range->bitrate[i] = supported_rates_by_vendor[i]*1000000;

	  }

	else
	  {
	     DEBUG("RATES B ONLY\n");

	     range->num_bitrates = 3;
	     for(i=0;i<3;i++)
	       range->bitrate[i] = supported_rates_by_vendor[i]*1000000;

	  }

     }

   DEBUG2("END get_range() ");

   return 0;
}

int test_get_power(struct net_device *dev,
			  struct iw_request_info *info, struct iw_param *vwrq, char *extra)
{
   vwrq->disabled = 1;
   return 0;
}
//get mode desde la estructura interna definida por el original
int test_get_mode(struct net_device *dev,
			 struct iw_request_info *info, __u32 *mode, char *extra)
{
   u8 BssType;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if (sme_get_bss_type(Adapter, &BssType) == -1)
     {

	sme_get_desired_bss_type(Adapter, &BssType);
     }

   switch(BssType)
     {

      case IBSS_NET :
	*mode = IW_MODE_ADHOC;
	break;
      case ESS_NET :
	*mode = IW_MODE_INFRA;
	break;
      case ANYBSS_NET :
	*mode = IW_MODE_AUTO;
	break;
      default:
	*mode= IW_MODE_INFRA;
	break;
     }
   return 0;

}

int test_set_mode(struct net_device *dev,
			 struct iw_request_info *info, __u32 *mode, char *extra)
{

   u8 BssType='\0';
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   int ret = 0;
   switch( *mode )
     {

      case IW_MODE_ADHOC :
	BssType = IBSS_NET;
	break;
      case IW_MODE_INFRA :
	BssType = ESS_NET;
	break;
      case IW_MODE_AUTO :
	BssType = ANYBSS_NET;
	break;
      case IW_MODE_MASTER :
	ret = -EOPNOTSUPP;
	break;
      case IW_MODE_REPEAT :
	ret = -EOPNOTSUPP;
	break;
      default :
	ret = -EINVAL;
	break;
     }

   sme_set_desired_bss_type(Adapter, BssType);
   DEBUG("Seteando BSSTYPE=%d\n",BssType);
   return ret;
}

int test_set_rate(struct net_device *dev,
			 struct iw_request_info *info, struct iw_param *rrq, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   if ( rrq->disabled != 1)
     {

	if (rrq->fixed != 0)
	  {

	     DEBUG("rate=%d\n",rrq->value);
	     switch(rrq->value)
	       {

		case 54:psLOCAL->TxRateMode = RATE_54M;break;
		case 48:psLOCAL->TxRateMode = RATE_48M;break;
		case 36:psLOCAL->TxRateMode = RATE_36M;break;
		case 24:psLOCAL->TxRateMode = RATE_24M;break;
		case 18:psLOCAL->TxRateMode = RATE_18M;break;
		case 12:psLOCAL->TxRateMode = RATE_12M;break;
		case 9:psLOCAL->TxRateMode = RATE_9M;break;
		case 6:psLOCAL->TxRateMode = RATE_6M;break;
		case 11:psLOCAL->TxRateMode = RATE_11M;break;
		case 2:psLOCAL->TxRateMode = RATE_2M;break;
		case 1:psLOCAL->TxRateMode = RATE_1M;break;
		case 0:psLOCAL->TxRateMode = RATE_AUTO;break;
		default:DEBUG("No Match Rate\n");break;
	       }

	     psLOCAL->CurrentTxRate = psLOCAL->TxRateMode;

	     DEBUG(" set Tx rate =%d ", psLOCAL->CurrentTxRate);

	  }

	else
	  {

	     psLOCAL->TxRateMode = RATE_AUTO;

	     DEBUG(" set auto Tx rate \n");

	  }

     }

   return 0;
}

int test_get_rate(struct net_device *dev,
			 struct iw_request_info *info, struct iw_param *rrq, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   rrq->value =  psLOCAL->CurrentTxRate * 500000;
   rrq->fixed = 1;
   return 0;

}

int test_set_rts(struct net_device *dev, struct iw_request_info *info,
			struct iw_param *rts, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if ( (rts->disabled != 1) && (rts->fixed != 0) )
     sme_set_rts_threshold(Adapter, rts->value );

   return 0;
}

int test_get_rts(struct net_device *dev, struct iw_request_info *info,
			struct iw_param *rts, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u32 RtsThreshold;
   sme_get_rts_threshold(Adapter, &RtsThreshold);
   rts->value = RtsThreshold;
   rts->disabled = 0;
   rts->fixed = 1;
   return 0;

}

int test_set_frag(struct net_device *dev, struct iw_request_info *info,
			 struct iw_param *frag, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if ( ( frag->disabled != 1) && (frag->fixed != 0 ) )
     sme_set_fragment_threshold(Adapter, frag->value );

   return 0;
}

int test_get_frag(struct net_device *dev, struct iw_request_info *info,
			 struct iw_param *frag, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u32 FragThreshold;

   sme_get_fragment_threshold(Adapter, &FragThreshold);
   frag->value = FragThreshold;
   frag->disabled = 0;
   frag->fixed = 0;
   return 0;
}

int test_set_txpow(struct net_device *dev, struct iw_request_info *info,
			  struct iw_param *txpower, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if ( (txpower->disabled != 1) && (txpower->fixed != 0) )
     sme_set_tx_power_level(Adapter, txpower->value);
   return 0;
}

int test_get_txpow(struct net_device *dev, struct iw_request_info *info,
			  struct iw_param *txpower, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u32   TxPower;

   DEBUG("GET TXPOWER\n");

   sme_get_tx_power_level(Adapter, &TxPower);

   txpower->value = TxPower;
   txpower->disabled = 0;
   txpower->fixed = 0;
   DEBUG("END TXPOWER");
   return 0;
}

int test_set_essid(struct net_device *dev,
		   struct iw_request_info *info, struct iw_point *data, char *essid)
{
	u8 		SSID[32]={0};
	PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

	DEBUG("SIOCSIWESSID test\n");

	if(psSME->encrypt_status >= ENCRYPT_TKIP)     {
		//To add the 64 HEX WPA
		u32 PasswordLength=strlen(pGlobal_STA_Wpa->WPAPassword);
		u8* Password=pGlobal_STA_Wpa->WPAPassword;
		u32 count=0;

		if(PasswordLength >= 64)
		{

# ifdef _WPA_PSK_DEBUG
			WBDEBUG(("The Password is too large \n"));
			//////////////////////////////////////////////
			//For Test
			WBDEBUG(("Dump password(1)\n"));
			DataDmp(Password,64,0);
# endif
			//////////////////////////////////////////////

			if(PasswordLength>64)
			{WBDEBUG(("The Password is >64 HEX \n"));return -EFAULT;}
			else
			{
				WBDEBUG(("The Password is =64 HEX \n"));
				for(count=0;count<32;count++)
				{
					Password[count]=((CharToBin(Password[count*2])<<4) | (CharToBin(Password[count*2+1])) );
				}
				OS_MEMORY_CLEAR(Password+32,32);

			}

			//////////////////////////////////////////////
			//For Test
# ifdef _WPA_PSK_DEBUG
			WBDEBUG(("Dump password(2)\n"));
			DataDmp(Password,64,0);
# endif
			//////////////////////////////////////////////

			//Copy the 64 Byte to pmk
			memcpy(pSTA->PMK.m_pmk, Password,32);
			//////////////////////////////////////////////////
		} else {
			memcpy(SSID,essid, data->length);
			AP_PrePasswordHash( Adapter, SSID, strlen(SSID) );
		}
	}

	sme_set_desired_ssid(Adapter,
			     essid,
			     data->length);
	return 0;
}

/* Segun el original no reporta el ssid conectado, veri los comentarios de codigo ahi */
int test_get_essid(struct net_device *dev,
			  struct iw_request_info *info, struct iw_point *data, char *essid)
{

   u8 SsidLen;
   u8 Ssid[33];
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   DEBUG("Asking for SSID");
   sme_get_desired_ssid( Adapter, Ssid, &SsidLen);
   Ssid[SsidLen]='\0';
   memcpy(essid, Ssid, SsidLen);
   data->flags = 1;
   data->length = SsidLen;

   return 0;
}

int test_get_sens(struct net_device *dev, struct iw_request_info *info,
			 struct iw_param *sens, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   s32 rssi;

   sme_get_rssi(Adapter, &rssi);
   sens->value = rssi & 0x3f;
   sens->fixed = 1;
   return 0;
}

int test_get_nick(struct net_device *dev, struct iw_request_info *info,
			 struct iw_point *data, char *nick)
{
   data->flags = 1;
   data->length = strlen(NICKNAME);
   strcpy(nick, NICKNAME);
   return 0;
}

int test_set_encode(struct net_device *dev,
			   struct iw_request_info *info, struct iw_point *erq, char *key)
{

   int index=0;
   int current_index=0;
   u8 KeyBuf[15];
   int default_key=0;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   DEBUG2("test_set_encode()\n");
   if( erq == NULL )
     return 0;

   if( erq->length > MAX_KEY_SIZE )
     return -E2BIG;

   index = (erq->flags & IW_ENCODE_INDEX ) - 1;

   DEBUG2("Flags: 0x%x WENCODE: 0x%x Resulting: %d\n",erq->flags,IW_ENCODE_INDEX,index);
   current_index =  psSME->_dot11WEPDefaultKeyID;
   //================ STAR PART
   if ((index < 0) || (index >= 4))
     {
	default_key = 1;
	DEBUG("Index: %d\n",index);
	index = current_index;
     }

   DEBUG2("Index OF: %d\n",index);
   if(erq->flags & IW_ENCODE_DISABLED & IW_ENCODE_MODE )
     {
	psSME->encrypt_status = WEP_DISABLE;	// disable encryption
	psSME->key_length =0;
	DEBUG2("WEP Disabled.....\n");
     }
   else
     {
	psSME->key_length = erq->length;
	DEBUG2("WEP Enabled.....\n");
	psSME->encrypt_status = ENCRYPT_WEP;
     }

   if(erq->flags & IW_ENCODE_RESTRICTED & IW_ENCODE_MODE)

     {
	DEBUG2("Shared -> restricted");
        psSME->bDesiredAuthMode = SHARE_AUTH;
     }
   else if( erq->flags & IW_ENCODE_OPEN & IW_ENCODE_MODE )
     {
	DEBUG("Open Auth\n");
	psSME->bDesiredAuthMode = OPEN_AUTH;
     }

   if (!(erq->flags & IW_ENCODE_NOKEY) )
     {
	DEBUG2("SETEANDO KEY....\n");
	memcpy( KeyBuf, key, erq->length);
	psSME->_dot11WEPDefaultKeyID = index;
	WBDEBUG(("set key index:%d\n",index));
	sme_set_add_wep( Adapter, index|0x80000000, erq->length, NULL, KeyBuf);

     }

         /* WE specify that if a valid key is set, encryption
		  * should be enabled (user may turn it off later)
		  * This is also how "iwconfig ethX key on" works */
   if ((index == current_index) && (psSME->key_length > 0) &&(psSME->bDesiredAuthMode == OPEN_AUTH))
     {
	psSME->bDesiredAuthMode = SHARE_AUTH;
     }
   sme_set_encryption_status( Adapter, psSME->encrypt_status );

   return 0;
}

int test_get_encode(struct net_device *dev,
			   struct iw_request_info *info, struct iw_point *erq, char *key)
{

   PADAPTER Adapter = dev->priv;
   int index ;

   DEBUG("test_get_encode");
   if( psSME->encrypt_status == WEP_DISABLE )
     erq->flags |= IW_ENCODE_DISABLED;
   else
     erq->flags |= IW_ENCODE_ENABLED;

   if( psSME->bDesiredAuthMode == OPEN_AUTH )
     erq->flags |= IW_ENCODE_OPEN;
   else
     erq->flags |= IW_ENCODE_RESTRICTED;

   index = (erq->flags & IW_ENCODE_INDEX) - 1;

   DEBUG("Index Recibido: %d\n",index);
   if((index < 0) || (index >= 4))
     index = psSME->_dot11WEPDefaultKeyID;

   DEBUG("INdex: %d\n",index);
   //key de transmision actual
   erq->flags |= index + 1;

   memcpy(key, &(Adapter->sHwData.Key_content[index][7]), Adapter->sHwData.CurrentDefaultKeyLength);

   erq->length = Adapter->sHwData.CurrentDefaultKeyLength;// psSME->key_length;

   DEBUG("Length: %d\n",erq->length);
   if( erq->length > 16)
     erq->length = 0;

   DEBUG("Length: %d\n",erq->length);

   return 0;
}

int test_set_encodeext(struct net_device *dev,
			      struct iw_request_info *info,
			      union iwreq_data *wrqu,
			      char *extra)
{
   NDIS_802_11_KEY			Key, * p;
   PADAPTER Adapter = dev->priv;
   struct iw_encode_ext*	ext  =   ( struct iw_encode_ext *)extra;
   struct iw_point *encoding = &wrqu->encoding;
   u8              *ptx_tsc = NULL;
   u8              *prx_tsc = NULL;
   u8               key_type = 0 ;
   u8				key_len = 0;

   if (ext == NULL)
     return -EINVAL;

   //# ifdef  _WPA_PSK_DEBUG
   DEBUG2("Dump SIOCSIWENCODEEXT :\n");
   // DataDmp(extra, encoding->length, 0);
   //# endif

   memset(&Key,0x00,sizeof(NDIS_802_11_KEY));
   p = &Key;

   DEBUG2("Algoritmo: %d\n",ext->alg);

   //------------------------------------------------------------
   if (ext->alg == IW_ENCODE_ALG_NONE)
     {
	if(encoding->flags & IW_ENCODE_DISABLED)
	  {
	     if(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
	       {
		  int keyindex = (encoding->flags & (~IW_ENCODE_DISABLED))-1;

		  if(keyindex<4)
		    {

		       DEBUG2("[w89c33 SIOCSIWENCODEEXT] ** remove group key %d\n",keyindex);

		       sme_remove_default_key(Adapter, keyindex);
		    }
	       }
	     else        // pairwise key
	       {
		  if( OS_MEMORY_COMPARE(ext->addr.sa_data,"\xff\xff\xff\xff\xff\xff",6) )
		    {
		       DEBUG2("[w89c33 SIOCSIWENCODEEXT] ** remove all pairwise key \n");

		       sme_clear_all_mapping_key(Adapter);
		    }
		  else
		    {

		       u8 rvbssid[6]={0};

		       memcpy(rvbssid,ext->addr.sa_data,6);
		       sme_remove_mapping_key(Adapter,rvbssid);
		    }
		  //pcore_data->ds_data.pairwise_key_ok = FALSE;
	       }
	  }

	if(ext != NULL)
	  {
	     DEBUG2("[w89c33 SIOCSIWENCODEEXT remove memory, return Memory in: 0x%p\n",&ext);
	     //kfree(ext) .... // * this will crash in original source... sould be removed by wpasup i think */
   return 0;

	  }
     }

   if (ext->alg == IW_ENCODE_ALG_WEP && ext != NULL)
     {
	return -EINVAL;
     }

   DEBUG2("Ndis Copy\n");

   // ACA ESTA EL ERROR
   //------------------------  Add Key (convert to NDIS rule) ----------------------
   p->KeyLength = encoding->length - ext->key_len;
   p->Length = ((void *) (p->KeyMaterial) - (void *) p) + p->KeyLength;
   memcpy(p->KeyMaterial, ext->key, p->KeyLength);
   // HASTA ACA ( ver exte->key_len _)
   //
   DEBUG2("Flag Based\n");
   if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
     {
	p->KeyIndex &= (~BIT(30));
	memcpy( p->BSSID, "\xff\xff\xff\xff\xff\xff", ETH_LENGTH_OF_ADDRESS );
     }
   else
     {
	p->KeyIndex |= BIT(30);
	memcpy(p->BSSID, ext->addr.sa_data, ETH_ALEN);
     }

   if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
     p->KeyIndex |= BIT(31);
   else
     p->KeyIndex &= (~BIT(31));

   if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
     {
	p->KeyIndex |= (BIT(29));
	memcpy (&(p->KeyRSC),ext->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);

     }
   else
     p->KeyIndex &= (~BIT(29));

   //p->KeyIndex &= (~BIT(28));      // NDIS rule set by authenticator,clear by supplicant so clear Bit(28)
   p->KeyIndex |= BIT(28);         // but wpa supplicant send the RX TX key diffrent from NDIS, so set again.

   // set group key index;
   if(encoding->flags>=1)
     {
	p->KeyIndex &= 0xffffff00;
	p->KeyIndex |= ((encoding->flags)-1);
     }
# ifdef  _WPA_PSK_DEBUG
   WBDEBUG(("key len = %d\n", p->KeyLength));
# endif

   //SetKeyStatus == MLME_SUCCESS;

   //ret = _drv_add_key(pcore_data, p);
   switch (p->KeyLength)
     {
      case 5:
	DEBUG2("Key Type = WEP40\n");
	key_type = HAL_KEYTYPE_WEP40;
	key_len = 5;
	//sme_set_encryption_status(Adapter, ENCRYPT_WEP);
	break;
      case 13:
	DEBUG2("Key Type = WEP104\n");
	key_type = HAL_KEYTYPE_WEP104;
	key_len = 13;
	//sme_set_encryption_status(Adapter, ENCRYPT_WEP);
	break;
      case 16:
	WBDEBUG(("Key Type = CCMP\n"));
	key_type = HAL_KEYTYPE_AES_CCMP;
	key_len = 16;
	//sme_set_encryption_status(Adapter, ENCRYPT_CCMP);
	break;
      case 32:
	DEBUG2("Key Type = TKIP\n");
	key_type = HAL_KEYTYPE_TKIP;
	key_len = 16;
	//sme_set_encryption_status(Adapter, ENCRYPT_TKIP);
	//SetKeyStatus == MLME_SUCCESS;
	break;
      default:
	DEBUG2("Key Type = UNKNOWN\n");
	//SetKeyStatus = FAILURE;
	break;
     }

   //TODO: ptx_rsc??
   if (p->KeyIndex & BIT(29))
     {
	// the KeyRSC should be used to set the initial receive
	// SC for the key when BIT 29 is set to 1.
	//
	// If the encryption cipher needs less bytes than supplied
	// by KeyRSC, the least significant bytes should be used.
	prx_tsc = (u8*) &p->KeyRSC;
     }
   DEBUG2("sme_daa_key");
   sme_add_key(Adapter,
	       p->KeyIndex,
	       key_len,
	       key_type,
	       p->BSSID,
	       ptx_tsc,
	       prx_tsc,
	       //p->KeyRSC,
	       p->KeyMaterial);

   return 0;
}

int test_get_encodeext(struct net_device *dev,
			      struct iw_request_info *info,
			      union iwreq_data *wrqu,
			      char *extra)
{

   return 0;
}

int test_get_wap(struct net_device *dev,
			struct iw_request_info *info, struct sockaddr *ap_addr, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u8   ConnectStatus;
   sme_get_connect_status(Adapter, &ConnectStatus);
   if (ConnectStatus == MEDIA_STATE_CONNECTED)
     {

	ap_addr->sa_family = ARPHRD_ETHER;        /* Ethernet 10Mbps */
	memset(&(ap_addr->sa_data), 0, 6);
	sme_get_bssid(Adapter, (u8*)&(ap_addr->sa_data));
     }
   else
     return -EINVAL;

   return 0;

}
int test_set_wap(struct net_device *dev,
			struct iw_request_info *info, struct sockaddr *ap_addr, char *extra)
{

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   DEBUG("|SetWap|\n");
   sme_set_desired_bssid(Adapter, ap_addr->sa_data);
   return 0;
}

int  test_get_register(struct net_device *dev,    struct iw_request_info *info, struct iw_param *param, char *extra){ return 0; }

int test_set_register(struct net_device *dev,    struct iw_request_info *info, struct iw_param *param, char *extra){ return 0; }       /* ZD1201GIWHOSTAUTH */

int test_get_region(	struct net_device *dev, struct iw_request_info *info,
				struct iw_point *data, char *region)
{

   u8   TmpBuf[15];
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   DEBUG("PRIVATE: GET_REGION");
   switch( psLOCAL->region )
     {

      case 0:
	strcpy( TmpBuf, "Reg_Unknown" );
	break;
      case 1:
	strcpy( TmpBuf, "Europe" );
	break;
      case 2:
	strcpy( TmpBuf, "Japan" );
	break;
      case 3:
	strcpy( TmpBuf, "USA" );
	break;
     }

   data->length = strlen(TmpBuf);
   strcpy( region,TmpBuf);
   data->flags = 1;

   return 0;

}
int test_set_region(	struct net_device *dev, struct iw_request_info *info,
				struct iw_point *data, char *region)
{
   u8 TmpValue[15];
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   if( !data )
     return 0;

   DEBUG("set region, size =%d  %s\n", data->length,region);

   memcpy( TmpValue, region, data->length);

   TmpValue[data->length] = '\0';

   if (!strcmp(TmpValue, "Reg_Unknown"))
     {

	psLOCAL->region = 0;
     }

   else if (!strcmp(TmpValue, "Europe"))
     {

	psLOCAL->region = 1;
     }

   else if (!strcmp(TmpValue, "Japan"))
     {

	psLOCAL->region = 2;
     }

   else if (!strcmp(TmpValue, "USA"))
     psLOCAL->region = 3;

   DEBUG("psLOCAL->region = %s\n",TmpValue);

   GetSupportChanRange(Adapter);
   GetIbssChan(Adapter);
   Scan_SetScanChanRange(Adapter, psSCANREQ);
   sme_set_disassociate(Adapter);
   return 0;

}
//No andan muy bien estos 2
int test_get_ibss_freq( struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *freq)
{
   u32 frequency;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u32 *freq_p = (u32 *) freq;

   DEBUG("IbssChanSetting.band =%d, ChanNo =%d\n",
	 psSME->IbssChan.band,
	 psSME->IbssChan.ChanNo);

   ChannelNumToFreq(psSME->IbssChan.band,
		    psSME->IbssChan.ChanNo, &frequency);

   data->length = 1;
   data->flags = 1;
   *freq_p = frequency;

   return 0;

}

int test_set_ibss_freq(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{
   u32 frequency;
   ChanInfo chan;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if( data == NULL)
     return 0;

   frequency =  *((u32 *)extra);

   if (frequency > 3000)
     chan.band = BAND_TYPE_OFDM_5;
   else
     chan.band = BAND_TYPE_OFDM_24;
   FreqToChannelNum(chan.band, &chan.ChanNo, frequency);
   sme_set_IBSS_chan(Adapter, chan);

   DEBUG(" Set IBSS frequency =%ul\n", frequency);

   return 0;

}

int test_get_ibss_mode(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)

{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   u8   TmpBuf[10];
   DEBUG("get_ibss_mode()\n");

   if (psLOCAL->bMacOperationMode == MODE_802_11_BG_IBSS)
     strcpy( TmpBuf, "IBSS_G" );
   else
     strcpy( TmpBuf, "IBSS_B" );

   data->length = strlen(TmpBuf);
   memcpy(extra, TmpBuf, data->length);

   return 0;
}

int test_set_ibss_mode(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{

   u8 TmpValue[10];

   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   memcpy( TmpValue, extra, data->length);
   TmpValue[data->length] = '\0';

   DEBUG("set_ibss_mode()\n");
   if (!strcmp(TmpValue, "IBSS_G"))
     {

	psLOCAL->bMacOperationMode = MODE_802_11_BG_IBSS;
     }

   else
     {

	psLOCAL->bMacOperationMode = MODE_AUTO;
     }

   return 0;

}
int test_scanning(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   DEBUG("SET Scan List");
   psSCAN->ScanTimeStamp++;
   sme_set_bssid_list_scan( Adapter, NULL );

   return 0;
}

int test_get_scan_list(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)

{
   DEBUG("GET SCAN LIST");
   return 0;
}

int test_set_pwd(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   if( data != NULL )
     {
	memcpy( pGlobal_STA_Wpa->WPAPassword, extra, data->length);

	//For debug
# ifdef _WPA_PSK_DEBUG
	DEBUG2("Set Password = %s\n", pGlobal_STA_Wpa->WPAPassword);
# endif
     }

   return 0;

}
int test_set_ie(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{

   u8 WPA_PSK_STRING[SSID_MAX_WPA_IE_LEN] ={0};
   u8 EncryptStatus = ENCRYPT_DISABLE;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;

   DEBUG2("SETTING IE\n");
   if( data == NULL )
     return 0;

# ifdef _WPA_PSK_DEBUG
   DEBUG("Dump IOCTL_PRIV_SET_GENIE String %s :\n", extra);
   DEBUG("Dump IOCTL_PRIV_SET_GENIE Size of String %d:\n", data->length);
   //DataDmp(wrq->u.data.pointer, wrq->u.data.length, 0);
# endif

   if( data->length > SSID_MAX_WPA_IE_LEN )
     return -E2BIG;

   memcpy( WPA_PSK_STRING, extra, data->length);

# ifdef _WPA_PSK_DEBUG
   WBDEBUG(("WPA_PSK_STRING String %s:\n", WPA_PSK_STRING ));
# endif

   if( !strcmp(WPA_PSK_STRING, "WPA_PSK_TKIP") )
     {
# ifdef _WPA_PSK_DEBUG
	WBDEBUG(("WPA_PSK TKIP:\n"));
# endif
	psSME->DesiredEncrypt=Cipher_Tkip;
	EncryptStatus = ENCRYPT_TKIP;
     }
   else if( !strcmp(WPA_PSK_STRING, "WPA_PSK_AES") )
     {
# ifdef _WPA_PSK_DEBUG
	WBDEBUG(("WPA_PSK AES:\n"));
# endif
	psSME->DesiredEncrypt=Cipher_Ccmp;
	EncryptStatus = ENCRYPT_CCMP;
     }
   else
     {
# ifdef _WPA_PSK_DEBUG
	WBDEBUG(("NO WPA_PSK :\n"));
# endif
     }

   if (EncryptStatus == ENCRYPT_TKIP || EncryptStatus == ENCRYPT_CCMP)
     {
	sme_set_auth_mode(Adapter, WPAPSK_AUTH);
	sme_set_encryption_status(Adapter, EncryptStatus);
     }

   return 0;

}
int test_get_ver(struct net_device *dev,    struct iw_request_info *info, struct iw_point *param, char *extra)
{
   const char *DriverVer=(char*)VER_FILEVERSION_STR; // 20060727
   memcpy( extra, DriverVer, sizeof(DriverVer));
   param->length = sizeof(DriverVer);

   return 0;
}
int test_get_ssid_info(struct net_device *dev,    struct iw_request_info *info, struct iw_point *param, char *extra)
{
   u8 ssid[32]={0};
   u8 ssid_len;
   PWB32_ADAPTER Adapter=(PWB32_ADAPTER)dev->priv;
   param->length = 0;
   if( !sme_get_ssid(Adapter, ssid, &ssid_len) )
     {
	if( sizeof(ssid)  <= 0 )
	  return 0;

	param->length = sizeof(ssid);
        memcpy( extra, ssid, param->length);

     }

   return 0;
}

int test_set_genie(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{
   short int pcout, kmcount;
   u8 wpaie[SSID_MAX_WPA_IE_LEN] = {0,};
   u8 EncryptStatus = ENCRYPT_DISABLE;
   PADAPTER Adapter = dev->priv;

   if (data->length > SSID_MAX_WPA_IE_LEN || extra == NULL)
     return -EINVAL;

# ifdef _PE_STATE_DUMP_
   WBDEBUG(("Dump SIOCSIWGENIE :\n"));
   DataDmp(extra, data->length, 0);
# endif

   memcpy(wpaie, extra, data->length);

   if(wpaie[0] == 221 && wpaie[1] > 12 )
     {
	if( !OS_MEMORY_COMPARE(&(wpaie[2]), "\x00\x50\xf2\x01", 4) )
	  {
	     return -EINVAL;
	  }

	// becasu set wpa always set 1 pairwise count
	if( !OS_MEMORY_COMPARE(&(wpaie[14]), "\x00\x50\xf2", 3) )
	  {
	     return -EINVAL;
	  }

	switch (wpaie[17])
	  {
	   case 2:
	     psSME->DesiredEncrypt=Cipher_Tkip;
	     EncryptStatus = ENCRYPT_TKIP;break;
	   case 4:
	     psSME->DesiredEncrypt=Cipher_Ccmp;
	     EncryptStatus = ENCRYPT_CCMP;break;
	   default:
	     break;
	  }

	// figo Notes: for capability information if occur
	// in associate requset, becasue wpa_supplicant 0.3.8 don't care capability inforation
	// so set this IOCTL we need re-write associate request wpa-capabiity inforamtion
	// relate two variable, rsn->rsn_capabilities, rsn->rsn_capabilities_valid;
	// set wpa ie -formate
	// |-ID-1-|-Len-1-|-oui-4|-ver-2-|-groupciper-4-|-pcount-2(always == 1)-|-4*pcount-|-kmcount-2(always=1)-|-4*kmcount-|-cap-2-|
	//
	pcout = *((short int *) (&(wpaie[12])));   // always 1
	kmcount = *((short int *) (&(wpaie[18])));

	if (data->length > (1 + 1 + 4 + 2 + 4 + 2 + (4 * pcout) + 2 + (4 * kmcount)))
	  {
	     ///psm_data->wpa_suplicant_capability = *((short int *)
	     ///                     (&(wpaie[1 + 1 + 4 + 2 + 4 + 2 + (4 * pcout) + 2 + (4 * kmcount)])));
	     ///psm_data->wpa_suplicant_capability_vaild = true;
	  }

	if (EncryptStatus == ENCRYPT_TKIP || EncryptStatus == ENCRYPT_CCMP)
	  {
	     sme_set_auth_mode(Adapter, WPAPSK_AUTH);
	     sme_set_encryption_status(Adapter, EncryptStatus);
	  }
	else
	  return -EINVAL;
     }
   else if(wpaie[0] == 48 && wpaie[1] >= 16)                   //WPA2 (RSN)
     {
	// WPA IE for RSN format
	// |-ID-1-|-Len-1-|-ver-2-|-groupciper-4-|-pcount-2(always == 1)-|-4*pcount-|-kmcount-2(always=1)-|-4*kmcount-|-cap-2-|
	pcout = *((short int *) (&(wpaie[8])));   // always 1
	kmcount = *((short int *) (&(wpaie[14])));

	if( !OS_MEMORY_COMPARE(&(wpaie[4]),"\x00\x0f\xac",3) )
	  return -EINVAL;

	switch (wpaie[13])
	  {
	   case 2:
	     psSME->DesiredEncrypt=Cipher_Tkip;
	     EncryptStatus = ENCRYPT_TKIP;break;
	   case 4:
	     psSME->DesiredEncrypt=Cipher_Ccmp;
	     EncryptStatus = ENCRYPT_CCMP;break;
	   default:
	     break;
	  }

	if (data->length > (1 + 1 + 2 + 4 + 2 + (4 * pcout) + 2 + (4 * kmcount)))
	  {
	     ///psm_data->wpa_suplicant_capability = *((short int *)
	     ///                  (&(wpaie[1 + 1 + 2 + 4 + 2 + (4 * pcout) + 2 + (4 * kmcount)])));
	     ///psm_data->wpa_suplicant_capability_vaild = true;
	  }

	if (EncryptStatus == ENCRYPT_TKIP || EncryptStatus == ENCRYPT_CCMP)
	  {
	     sme_set_auth_mode(Adapter, WPA2PSK_AUTH);
	     sme_set_encryption_status(Adapter, EncryptStatus);
	  }
	else
	  {
	     return -EINVAL;
	  }
     }
   else
     return -EINVAL;

   return 0;
}

//crashea aca
int test_set_auth(struct net_device *dev,    struct iw_request_info *info, struct iw_point *data, char *extra)
{

   PADAPTER Adapter = dev->priv;
   u16             ath_index;
   s32             value = 0;//  extra;

   DEBUG2("Test Auth\n");

   if( data == NULL )
     return -EINVAL;

   if( data->pointer != NULL )
     {

	value = (s32)(data->pointer);
     }

   ath_index = data->flags;

   DEBUG2("(test_set_auth)  Auth Idx =%d, value = %ld\n", ath_index, value);
   switch( ath_index )
     {

      case IW_AUTH_80211_AUTH_ALG:
	if (IW_AUTH_ALG_OPEN_SYSTEM == value)
	  sme_set_auth_mode(Adapter, OPEN_AUTH);
	else if (IW_AUTH_ALG_SHARED_KEY == value)
	  sme_set_auth_mode(Adapter, SHARE_AUTH);
	break;
      case IW_AUTH_WPA_ENABLED :
	if (value == 0) //disable
	  {

	     sme_set_disassociate( Adapter );
	     sme_set_auth_mode(Adapter, OPEN_AUTH);
	     sme_set_encryption_status(Adapter, ENCRYPT_DISABLE);
	  }

	break;
      default :
	break;
     }

   return 0;

}

/*
# ifdef DEBUG_MINE_1

struct iw_statistics *test_get_wireless_stats(struct net_device *dev)
{

   PADAPTER Adapter = dev->priv;
   struct iw_statistics *iw_stats = &Adapter->iw_stats;
//   unsigned int i, count;
  unsigned int t_rssi, t_qual;

   memset(iw_stats, 0, sizeof(struct iw_statistics));

   //SIMULATION for test......

   //lock..?

   t_rssi = t_qual = 0;

   iw_stats->qual.updated = IW_QUAL_NOISE_INVALID;

   iw_stats->qual.qual = 99;
   iw_stats->qual.level = 99;
   iw_stats->qual.updated |=
     IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED;

   return iw_stats;
}
#endif 


#endif

*/
